//
//  MsgRootController.m
//  Ten
//
//  Created by anfuer on 2018/8/25.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "MsgRootController.h"
#import "MsgCell.h"
#import "WhoLookMeController.h"
@interface MsgRootController ()

{
    NSArray*dataary;
}
@property (weak, nonatomic) IBOutlet UITableView *tbv;
@property (weak, nonatomic) IBOutlet UIImageView *img1;
@property (weak, nonatomic) IBOutlet UIImageView *img2;
@property (weak, nonatomic) IBOutlet UILabel *lb1;
@property (weak, nonatomic) IBOutlet UILabel *lb2;
@property (weak, nonatomic) IBOutlet UILabel *lb3;
@property (weak, nonatomic) IBOutlet UILabel *lb4;
@property (weak, nonatomic) IBOutlet UIView *hidenview;



@end

@implementation MsgRootController
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:NO];
    _tbv.separatorColor=[UIColor clearColor];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    [FuncPublic getData:self parameters:nil RequestUrl:Xmy_messages success:^(NSDictionary *acountInfo) {
        dataary=acountInfo[@"chats"];
        _hidenview.hidden=dataary.count;
        [_tbv reloadData];
        NSDictionary*dic=acountInfo[@"system_messages_last"];
        _lb1.text=WXGStr(dic[@"add_time"]);
        _lb2.text=WXGStr(dic[@"content"]);
        NSDictionary*dic2=acountInfo[@"resume_messages_last"];
        _lb3.text=WXGStr(dic2[@"add_time"]);
        _lb4.text=[[dic2 allKeys]containsObject:@"content"]?WXGStr(dic2[@"content"]):@"暂无浏览记录";
        
    }];
 
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  dataary.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
    static NSString *ID = @"MsgCell";
    MsgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary*dict=dataary[indexPath.row];
    [cell.img sd_setImageWithURL:[dict[@"company"][@"logo"] formatUrl] placeholderImage:WXGImage(@"zhanwei")];
    cell.lb1.text=WXGStr(dict[@"company"][@"name"]);
     cell.lb2.text=WXGStr(dict[@"add_time_str"]);
     cell.lb3.text=WXGStr(dict[@"message"]);
    return cell;

}


#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 90;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

        [MyUtils collviewSelidex:@"公司详情" toVc:self andShopInfo:dataary[indexPath.row]];
}


//tag=1 系统消息  tag=2 谁看过我
- (IBAction)lookMeBtna:(UIButton *)sender {
    if (sender.tag==1) {
          [MyUtils collviewSelidex:@"消息详情" toVc:self andShopInfo:nil];
    }else
    {
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"dy" bundle:nil];
        WhoLookMeController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"WhoLookMe"];
        [self.navigationController pushViewController:secondViewController animated:YES];
    
    }
}



@end
